package com.wang.cloud.common.swagger;

import cn.hutool.core.collection.CollectionUtil;
import com.wang.cloud.common.swagger.customizers.MyOperationCustomizer;
import com.wang.cloud.common.swagger.customizers.SchemaEnumPropertyCustomizer;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import java.util.ArrayList;
import java.util.List;


/**
 * @author wangye
 * @date 2023/7/11 0011
 */
@Configuration
@Slf4j
@Import({SchemaEnumPropertyCustomizer.class})
public class EnableAutoConfiguration {

    @PostConstruct
    public void init() {
        log.info("加载common-swagger模块");
    }

    @Bean
    public MyOperationCustomizer myOperationCustomizer(List<GroupedOpenApi> groupedOpenApiList) {
        MyOperationCustomizer customizer = new MyOperationCustomizer();
        ArrayList<MyOperationCustomizer> list = CollectionUtil.toList(customizer);
        for (GroupedOpenApi api : groupedOpenApiList) {
            api.addAllOperationCustomizer(list);
        }
        return customizer;
    }

}
